package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ResDish;
import com.ruoyi.system.service.IResDishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐馆菜品Controller
 * 
 * @author ruoyi
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/system/resdish")
public class ResDishController extends BaseController
{
    @Autowired
    private IResDishService resDishService;

    /**
     * 查询餐馆菜品列表
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResDish resDish)
    {
        startPage();
        List<ResDish> list = resDishService.selectResDishList(resDish);
        return getDataTable(list);
    }

    /**
     * 导出餐馆菜品列表
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:export')")
    @Log(title = "餐馆菜品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResDish resDish)
    {
        List<ResDish> list = resDishService.selectResDishList(resDish);
        ExcelUtil<ResDish> util = new ExcelUtil<ResDish>(ResDish.class);
        util.exportExcel(response, list, "餐馆菜品数据");
    }

    /**
     * 获取餐馆菜品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:query')")
    @GetMapping(value = "/{dishId}")
    public AjaxResult getInfo(@PathVariable("dishId") Long dishId)
    {
        return success(resDishService.selectResDishByDishId(dishId));
    }

    /**
     * 新增餐馆菜品
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:add')")
    @Log(title = "餐馆菜品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResDish resDish)
    {
        return toAjax(resDishService.insertResDish(resDish));
    }

    /**
     * 修改餐馆菜品
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:edit')")
    @Log(title = "餐馆菜品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResDish resDish)
    {
        return toAjax(resDishService.updateResDish(resDish));
    }

    /**
     * 删除餐馆菜品
     */
    @PreAuthorize("@ss.hasPermi('system:resdish:remove')")
    @Log(title = "餐馆菜品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishIds}")
    public AjaxResult remove(@PathVariable Long[] dishIds)
    {
        return toAjax(resDishService.deleteResDishByDishIds(dishIds));
    }
}
